package com.adinnet.api.peaseRule.controller;


import com.adinnet.api.peaseRule.model.PeaseRule;
import com.adinnet.api.peaseRule.service.PeaseRuleService;
import com.adinnet.common.utils.StringUtil;
import com.adinnet.core.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 金豆规则 前端控制器
 * </p>
 *
 * @author chenjia
 * @since 2020-12-10
 */
@RestController
@RequestMapping("api/peaseRule")
public class PeaseRuleController {


    @Autowired
    private PeaseRuleService peaseRuleService;

    /**
     *查询所有金豆规则
     * @return
     */
    @GetMapping("getAllPeaseRule")
    public JsonResult getAllPeaseRule() {
        try {
            List<PeaseRule> peaseRules = peaseRuleService.getAllPeaseRule();
            return JsonResult.ok().put("data",peaseRules);
        }catch (Exception e){
            return JsonResult.error("获取失败");
        }
    }


    /**
     *根据唯一编码查询金豆规则
     * @return
     */
    @GetMapping("getPeaseRuleByCode")
    public JsonResult getPeaseRuleByCode(@RequestParam(value = "code")String code) {
        try {
            if(StringUtil.isBlank(code)){
                return JsonResult.error("获取失败:唯一编码不能为空");
            }
            PeaseRule peaseRules = peaseRuleService.getPeaseRuleByCode(code);
            return JsonResult.ok().put("data",peaseRules);
        }catch (Exception e){
            return JsonResult.error("获取失败");
        }
    }

}
